#!/usr/bin/env bash
#
# Copyright (c) 2023 - 2025 Restate Software, Inc., Restate GmbH.
# All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
#

set -euo pipefail
exit_code=0
files=$(find crates cli server -name "*.rs") || exit 1
for file in ${files}; do
    if ! head -9 "$file" | tr -d '\n' | grep -q '^// Copyright (c) [0-9]\{4\}\( - [0-9]\{4\}\)\? \+Restate Software, Inc., Restate GmbH.// All rights reserved.//// Use of this software is governed by the Business Source License// included in the LICENSE file.//// As of the Change Date specified in that file, in accordance with// the Business Source License, use of this software will be governed// by the Apache License, Version 2.0.$'; then
        echo "$file does not contain valid license header"
        exit_code=1
    fi
done
exit $exit_code
